//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2010
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.Collections;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security;
using DotNetNuke.Services.Scheduling;
namespace DotNetNuke.Modules.Admin.Scheduler
{
	partial class ViewSchedule : Entities.Modules.PortalModuleBase, Entities.Modules.IActionable
	{
		protected string GetTimeLapse(int TimeLapse, string TimeLapseMeasurement)
		{
			if (TimeLapse != Null.NullInteger) {
				string str = Null.NullString;
				string strPrefix = Services.Localization.Localization.GetString("TimeLapsePrefix", this.LocalResourceFile);
				string strSec = Services.Localization.Localization.GetString("Second", this.LocalResourceFile);
				string strMn = Services.Localization.Localization.GetString("Minute", this.LocalResourceFile);
				string strHour = Services.Localization.Localization.GetString("Hour", this.LocalResourceFile);
				string strDay = Services.Localization.Localization.GetString("Day", this.LocalResourceFile);
				string strSecs = Services.Localization.Localization.GetString("Seconds");
				string strMns = Services.Localization.Localization.GetString("Minutes");
				string strHours = Services.Localization.Localization.GetString("Hours");
				string strDays = Services.Localization.Localization.GetString("Days");
				switch (TimeLapseMeasurement) {
					case "s":
						str = strPrefix + " " + TimeLapse.ToString() + " " + (TimeLapse > 1 ? strSecs : strSec);
						break;
					case "m":
						str = strPrefix + " " + TimeLapse.ToString() + " " + (TimeLapse > 1 ? strMns : strMn);
						break;
					case "h":
						str = strPrefix + " " + TimeLapse.ToString() + " " + (TimeLapse > 1 ? strHours : strHour);
						break;
					case "d":
						str = strPrefix + " " + TimeLapse.ToString() + " " + (TimeLapse > 1 ? strDays : strDay);
						break;
				}
				return str.ToString();
			} else {
				return Services.Localization.Localization.GetString("n/a", this.LocalResourceFile);
			}
		}
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			try {
				if (!Page.IsPostBack) {
					ArrayList arrSchedule = SchedulingProvider.Instance().GetSchedule();
					Services.Localization.Localization.LocalizeDataGrid(ref dgSchedule, this.LocalResourceFile);
					dgSchedule.DataSource = arrSchedule;
					dgSchedule.DataBind();
				}
			} catch (Exception exc) {
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		public ModuleActionCollection ModuleActions {
			get {
				ModuleActionCollection Actions = new ModuleActionCollection();
				Actions.Add(GetNextActionID(), Services.Localization.Localization.GetString(ModuleActionType.AddContent, LocalResourceFile), ModuleActionType.AddContent, "", "add.gif", EditUrl(), false, SecurityAccessLevel.Host, true, false);
				Actions.Add(GetNextActionID(), Services.Localization.Localization.GetString(ModuleActionType.ContentOptions, LocalResourceFile), ModuleActionType.AddContent, "", "icon_scheduler_16px.gif", EditUrl("", "", "Status"), false, SecurityAccessLevel.Host, true, false);
				Actions.Add(GetNextActionID(), Services.Localization.Localization.GetString("ScheduleHistory.Action", LocalResourceFile), ModuleActionType.AddContent, "", "icon_profile_16px.gif", EditUrl("", "", "History"), false, SecurityAccessLevel.Host, true, false);
				return Actions;
			}
		}
	}
}
